package cn.hh.wechatkit.pojo.card.enums;

import cn.hh.wechatkit.exception.Wx_Exception_InvalidParam;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * Created this one by HMH on 2017/7/4.
 * code类型，用于描述卡券的核销方式
 */

@Getter
public enum Wx_CodeTypeEnum {

    CODE_TYPE_QRCODE("用于扫码和输入"),
    CODE_TYPE_ONLY_QRCODE("仅扫码"),
    CODE_TYPE_TEXT("仅输入"),
    CODE_TYPE_NONE("线上核销")
    ;
    String msg;

    Wx_CodeTypeEnum(String msg) {
        this.msg = msg;
    }

    private static final Map<String, Wx_CodeTypeEnum> stringToEnum = new HashMap<>();
            static{
                for(Wx_CodeTypeEnum e : values()){
                    stringToEnum.put(e.name(), e);
                }
            }

            public static Wx_CodeTypeEnum fromString(String name,String fieldName){
                Wx_CodeTypeEnum result = stringToEnum.get(name);
                if (result == null) {
                    throw new Wx_Exception_InvalidParam(fieldName+"枚举字段错误");
                }
                return result;
            }
}
